package com.meilai.project.controller.web.workPlatform.vo;

import com.meilai.project.constant.WorkPlatformCalendarEventLevelEnum;
import com.meilai.project.constant.WorkPlatformCalendarEventTypeEnum;
import com.meilai.project.entity.business.customer.CustomerInfo;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 张驰
 * @description 日程-事件
 * @date 2022-09-07 11:18
 */
@Data
public class CalendarEventVO {
    private String id;
    private String title;
    private String start;
    private String end;
    private String className;
    private Boolean allDay = true;
    private String desp;
    private Integer type;
    private String typeName;

    /**
     * 生成 客户拜访 类型的日程事件
     * @param userId 用户id
     * @param customers 客户s
     */
    public static List<CalendarEventVO> genCustomerFollowEvent(Long userId, List<CustomerInfo> customers){
        List<CalendarEventVO> result = new ArrayList<>();

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        WorkPlatformCalendarEventTypeEnum curEnum = WorkPlatformCalendarEventTypeEnum.CUSTOMER_FOLLOW;

        if(CollectionUtils.isEmpty(customers)) return result;

        for (CustomerInfo customer : customers) {
            if(customer.getNext_visit_time() == null) continue;
            String day = dtf.format(customer.getNext_visit_time());

            CalendarEventVO cur = new CalendarEventVO();
            cur.setId(WorkPlatformCalendarEventTypeEnum.genEventUUID(curEnum, userId, customer.getId()));
            cur.setTitle(genTitle(curEnum, customer.getName()));
            cur.setStart(day);
            cur.setEnd(day);
            cur.setClassName(WorkPlatformCalendarEventLevelEnum.NORMAL.getClassName());
            cur.setType(curEnum.getId());
            cur.setTypeName(curEnum.getName());
            result.add(cur);
        }

        return result;
    }

    private static String genTitle(WorkPlatformCalendarEventTypeEnum curEnum, String subTitle){
        return curEnum.getName()+"："+subTitle;
    }
}
